from sqlalchemy import create_engine, Column, Integer, String, DateTime, DECIMAL, ForeignKey, TIMESTAMP, Boolean, Table
from base import Base
from sqlalchemy.sql import func


class AdminUser(Base):
    __tablename__ = 'admin_users'
    id = Column(Integer, primary_key=True, index=True)
    username = Column(String(255), unique=True, index=True, comment="姓名")
    avatar = Column(String(255), unique=True, index=True, comment="头像")
    hashed_password = Column(String(255), comment="哈希密码")
    email = Column(String(255), unique=True, index=True, comment="电子邮件")
    status = Column(Integer,  default=1, comment="0 禁用 1 正常")
    created_at = Column(DateTime(timezone=True), server_default=func.now(), comment='创建时间')
    updated_at = Column(DateTime(timezone=True), onupdate=func.now(), comment='更新时间')
    deleted_at = Column(DateTime, comment='更新时间')

    user_role_association = Table(
        'admin_user_roles',
        Base.metadata,
        Column('admin_user_id', Integer, ForeignKey('admin_users.id')),
        Column('role_id', Integer, ForeignKey('roles.id'))
    )
